const path = require('path')
const config = require('./config')
const common = require('./common')

var computerIP = config.computerIP
var defaultProjectName = config.projectName

var getFileList = folderPath => {
	var fileList = common.getFileList(folderPath)
	return fileList
}

var filePathToUrl = filePath => {
	filePath = filePath.replace(
		syncFolder,
		computerIP + ':3000/fileSync/fileDownload/' + syncFolder.split('/')[syncFolder.split('/').length - 1]
	)
	return filePath
}
var projectFileList = projectName => {
	if (!projectName) {
		projectName = defaultProjectName
	}
	console.log(`当前要同步的项目是: ${projectName}`)
	var folderPath = path.join(`./${projectName}`)
	console.log(`folderPath = ${folderPath}`)
	var fileList = getFileList(folderPath)
	return fileList
}

module.exports = {
	getFileList: getFileList,
	filePathToUrl: filePathToUrl,
	projectFileList: projectFileList,
	readFile: common.readFile,
}
